package com.yang.imbatis.factory;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Controller;

/**
 * @Description: 这个类注入到spring容器里面并且会给容器一个类, 也就是getObject方法
 * @author: Yang Qiang
 * @create: 2021-10-18 21:27
 */

public class YangFactoryBean implements FactoryBean {
	// 属性就是mapper接口
	Class mapperInterface;


	public YangFactoryBean() {
	}

	public YangFactoryBean(Class mapperInterface) {
		this.mapperInterface = mapperInterface;
	}

	public void setMapperInterface(Class mapperInterface) {
		this.mapperInterface = mapperInterface;
	}

	/**
	 * 仔细看代码, 使用调用我们自己定义的获取代理对象的方法
	 * 实例化这个对象的时候, 会调用这个方法, 然后就会返回一个对象实例到spring容器中
	 * @return
	 * @throws Exception
	 */
	@Override
	public Object getObject() throws Exception {
		YangSession session = new YangSession();
		Object mapper = session.getMapper(mapperInterface);
		return mapper;
	}

	@Override
	public Class<?> getObjectType() {
		return mapperInterface;
	}


}
